package com.qqt.csr.route.service;

import com.qqt.csr.common.exception.StatusCode;
import com.qqt.csr.common.utils.ServiceAssert;
import com.qqt.csr.route.dto.resp.RouteResultDTO;
import com.qqt.csr.route.entity.RouteTask;
import com.qqt.csr.route.enums.CsDistributionTypeEnum;
import com.qqt.csr.route.enums.RouteTaskEventEnum;
import com.qqt.csr.route.service.strategy.cs.ICsDistribution;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 客服分配
 *
 * @author
 */
@Slf4j
@Service
public class RouteCsService {

    /**
     * 根据客服接入策略，获取在线客服
     *
     * @param routeTask
     * @param resultDTO
     */
    public void route(RouteTask routeTask, RouteResultDTO resultDTO) {
        CsDistributionTypeEnum distributionTypeEnum = CsDistributionTypeEnum.getByValue(routeTask.getSkillSet().getRoutePolicy());
        ServiceAssert.notNull(distributionTypeEnum, StatusCode.Common.NOT_EXIST.getCode(), "无效技能组配置！", String.format("无效技能组配置, skillSetId:%s", routeTask.getSkillSet().getSkillSetId()));

        ICsDistribution csDistribution = distributionTypeEnum.getCsDistribution();
        csDistribution.distribution(routeTask, resultDTO);
        if(resultDTO.getCsInfo() != null){
            routeTask.addEvent(RouteTaskEventEnum.DIRECTLY_SEAT);
            routeTask.setCsId(resultDTO.getCsInfo().getUserId());
        }
    }


}
